package leetcode_周赛._2021._202106._20210606;

import java.util.*;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/6/6 10:39
 * 使数组元素相等的减少操作次数
 * 算法：排序
 * a 变换到最小的值需要找到比它小的数字的个数
 */
public class _5777 {
    public static void main(String[] args) {
    }

    public int reductionOperations(int[] nums) {
        if (nums.length <= 1) return 0;
        Arrays.sort(nums);
        int m = nums.length;
        int[] dp = new int[m];
        for (int i = 1; i < m; i++) {
            dp[i] = dp[i - 1];
            if (nums[i] > nums[i - 1]) dp[i] = dp[i - 1] + 1;
        }
        int ans = 0;
        for (int i : dp) ans += i;
        return ans;
    }

}
